package com.cn.string;

import java.util.Scanner;

/**
 * 3. 用Scanner获取用户输入
 * Scanner sc = new Scanner(System.in);
 * String scUsername = sc.nextLine();
 */
public class String_03_Scanner {
    public static void main(String[] args) {
        //1. 已知用户名和密码，定义两个字符串表示即可
        String username = "admin";
        String password = "123456";

        //2. 键盘录入要登录的用户名和密码，用Scanner实现
        Scanner sc = new Scanner(System.in);

        //3. 用循环实现多次机会，这里的次数明确，采用for循环实现
        for (int i = 0; i < 3; i++) {
            System.out.println("请输入用户名:");
            String inputUsername = sc.nextLine();
            System.out.println("请输入密码:");
            String inputPassword = sc.nextLine();

            if(username.equals(inputUsername) && password.equals(inputPassword)){
                System.out.println("登录成功");
                break;
            }else{
                if(i == 2){
                    System.out.println("您的登录次数已达到今日上限, 请明天再来");
                }else{
                    System.out.println("登录失败,您还剩余" + (2-i) +"次机会");
                }
            }

        }

    }
}
